package ai.application;

import ai.spatial.Vector2D;

public class Environment {

	private double minX;
	private double minY;
	private double maxX;
	private double maxY;

	public Environment(double minX, double minY, double maxX, double maxY){
		this.minX = minX;
		this.minY = minY;
		this.maxX = maxX;
		this.maxY = maxY;
	}
	
	public boolean checkCollision(Vector2D newPosition) {
		if (newPosition.getX() < this.getMinX()) {
			return true;
		}
		if (newPosition.getY() < this.getMinY()) {
			return true;
		}
		if (newPosition.getX() > this.getMaxX()) {
			return true;
		}
		if (newPosition.getY() > this.getMaxY()) {
			return true;
		}
		return false;
	}

	public double validateVelocity(double newVelocityX, double newVelocityY) {

		double v = Math.hypot(newVelocityX, newVelocityY);
		if (v > Config.MAX_V) {
			return Config.MAX_V / v;
		}
		return 1;
	}
	
	public double getMinX() {
		return minX;
	}
	
	public double getMinY() {
		return minY;
	}
	
	public double getMaxX() {
		return maxX;
	}
	
	public double getMaxY() {
		return maxY;
	}
}
